// // worker-timer.js
// class WorkerTimer {
//   constructor() {
//     const workerScript = `
//       let tasks = {};
//       let taskIdCounter = 0;

//       self.onmessage = function(e) {
//         const { type, ms, callbackId } = e.data;

//         if (type === 'setTimeout') {
//           const taskId = taskIdCounter++;
//           tasks[taskId] = setTimeout(() => {
//             self.postMessage({ type: 'timeout', id: taskId, callbackId });
//             delete tasks[taskId];
//           }, ms);
//         } else if (type === 'setInterval') {
//           const taskId = taskIdCounter++;
//           tasks[taskId] = setInterval(() => {
//             self.postMessage({ type: 'interval', id: taskId, callbackId });
//           }, ms);
//         } else if (type === 'clearTimeout' || type === 'clearInterval') {
//           const taskId = e.data.id;
//           if (tasks[taskId]) {
//             if (type === 'clearTimeout') {
//               clearTimeout(tasks[taskId]);
//             } else if (type === 'clearInterval') {
//               clearInterval(tasks[taskId]);
//             }
//             delete tasks[taskId];
//           }
//         }
//       };
//     `
//     const blob = new Blob([workerScript], { type: "application/javascript" })
//     this.worker = new Worker(URL.createObjectURL(blob))
//     this.callbacks = {}
//     this.taskIdCounter = 0

//     this.worker.onmessage = (e) => {
//       const { type, id, callbackId } = e.data
//       if (this.callbacks[callbackId]) {
//         this.callbacks[callbackId]()
//         if (type === "timeout") {
//           delete this.callbacks[callbackId]
//         }
//       }
//     }
//   }

//   static getInstance() {
//     if (!WorkerTimer.instance) {
//       WorkerTimer.instance = new WorkerTimer()
//     }
//     return WorkerTimer.instance
//   }

//   static setTimeout(callback, ms) {
//     const instance = WorkerTimer.getInstance()
//     const callbackId = instance.taskIdCounter++
//     instance.callbacks[callbackId] = callback
//     instance.worker.postMessage({ type: "setTimeout", ms, callbackId })
//     return callbackId
//   }

//   static setInterval(callback, ms) {
//     const instance = WorkerTimer.getInstance()
//     const callbackId = instance.taskIdCounter++
//     instance.callbacks[callbackId] = callback
//     instance.worker.postMessage({ type: "setInterval", ms, callbackId })
//     return callbackId
//   }

//   static clearTimeout(id) {
//     const instance = WorkerTimer.getInstance()
//     instance.worker.postMessage({ type: "clearTimeout", id })
//     delete instance.callbacks[id]
//   }

//   static clearInterval(id) {
//     const instance = WorkerTimer.getInstance()
//     instance.worker.postMessage({ type: "clearInterval", id })
//     delete instance.callbacks[id]
//   }
// }

// export default WorkerTimer
